import Vue from 'vue';
import VueMeta from 'vue-meta';
import { sync } from 'vuex-router-sync';
import App from './App.vue';
import createRouter from './router';
import createStore from './store';
import 'vant/lib/icon/local.css';
import './assets/css/van-reset.less';
import 'swiper/css/swiper.css';
import './assets/css/mall.less';
import global from './utils/global.js';
import {
  formatDate, formatZdf, fixedNumber, formatMoneyUnit, formatPercent, numberComma, yieldFormat, numHidden
} from './utils/filters';

if (process.env.VUE_APP_ENV === 'client' || process.env.VUE_APP_ENV === 'front') {
  require('./assets/js/jssdk-zzb-0.0.1.js');
  // if (process.env.NODE_ENV !== 'production') {
  // const eruda = require('eruda');
  // eruda.init();
  // }
}

Vue.use(global);
Vue.use(VueMeta, {
  refreshOnceOnNavigation: true,
});
Vue.filter('formatDate', formatDate);
Vue.filter('formatZdf', formatZdf);
Vue.filter('fixedNumber', fixedNumber);
Vue.filter('formatMoneyUnit', formatMoneyUnit);
Vue.filter('formatPercent', formatPercent);
Vue.filter('numberComma', numberComma);
Vue.filter('yieldFormat', yieldFormat);
Vue.filter('numHidden', numHidden);

export default function createApp() {
  // 创建 router 和 store 实例
  const router = createRouter();
  const store = createStore();

  // 同步路由状态(route state)到 store
  sync(store, router);

  // 创建应用程序实例，将 router 和 store 注入
  const app = new Vue({
    router,
    store,
    metaInfo: {
      title: '聚宝盆',
      // titleTemplate: '%s-聚宝盆',
      meta: [
        { name: 'chartset', content: 'utf-8' },
        { name: 'keywords', content: '聚宝盆,聚宝盆,聚宝盆,' },
        { name: 'description', content: '聚宝盆,聚宝盆,聚宝盆,聚宝盆,聚宝盆,聚宝盆,聚宝盆,聚宝盆,聚宝盆,' },
      ]
    },
    render: h => h(App)
  });

  // 暴露 app, router 和 store。
  return { app, router, store };
}